#include <iostream>
#include <queue>
#include <unordered_map>
using namespace std;

int mMax, nMax, d;

struct bottleStatus {
    int m;
    int n;
    public : bottleStatus(int m, int n) {
        this->m = m;
        this->n = n;
    }
};


int boardSearchWater(int target) {
    unordered_map<string, int> bottleMap;
    queue<bottleStatus> status;
    bottleStatus startUp(0, 0);
    status.push(startUp);
    int times = 0;
    while (!status.empty()) {
        queue<bottleStatus> temp;
        while (!status.empty()) {
            bottleStatus curr = status.front();
            if (curr.m == target || curr.n == target) {
                return times;
            }
            status.pop();
            string counter = to_string(curr.m) + to_string(curr.n);
            if (bottleMap.find(counter) == bottleMap.end()) {
                // 装水
                temp.push(bottleStatus(mMax, curr.n));
                temp.push(bottleStatus(curr.m, nMax));
                // 倒水
                temp.push(bottleStatus(0, curr.n));
                temp.push(bottleStatus(curr.m, 0));
                // 互相倒水
                temp.push(bottleStatus(curr.m + curr.n > nMax ? curr.m - (nMax - curr.n) : 0,
                curr.m + curr.n > nMax ? nMax : curr.n + curr.m));
                // m 倒入 n
                temp.push(bottleStatus(curr.m + curr.n > mMax ? mMax : curr.m + curr.n,
                curr.m + curr.n > mMax ? curr.n - (mMax - curr.m) : 0));
                // n 倒入 m
                bottleMap.insert(pair<string, int>(counter, 1));
            }
        }
        status = temp;
        times++;
    }
    return -1;
}

int main() {
    scanf("%d%d%d", &mMax, &nMax, &d);
    printf("%d", boardSearchWater(d));
    return 0;
}